<template>
  <div class="form-elements">
    <div class="row">
      <div class="flex xs12">
        <va-card :title="'编辑用户信息'">
          <form>
<!--            <div class="row">-->
<!--              <div class="flex md3 sm6 xs12">-->
<!--                <va-input-->
<!--                  v-model="date"-->
<!--                  type="date"-->
<!--                  :label="'日期'"-->
<!--                />-->
<!--              </div>-->
<!--              <div class="flex md3 sm6 xs12">-->
<!--                <va-input-->
<!--                  v-model="time"-->
<!--                  type="time"-->
<!--                  :label="'时间'"-->
<!--                />-->
<!--              </div>-->
<!--            </div>-->
            <div class="row">
              <div class="flex md3 sm6 xs12">
                <va-input
                  v-model="username"
                  type="text"
                  :label="'用户名'"
                />
              </div>




              <div class="flex md3 sm6 xs12">
                <va-input
                  v-model="role"
                  type="text"
                  :label="'权限'"
                />
              </div>
            </div>

            <div class="row">
              <va-button @click="subadd">提交</va-button>
              <va-button @click="back">返回</va-button>
            </div>
          </form>
        </va-card>
      </div>
    </div>
  </div>
</template>

<script>
  export default {
    name: 'form-elements',
    data () {
      return {
        username:'',
        role:''
      }
    },
    created(){
      // if(!this.$route.params.id)
      //   this.$router.push({ name: 'dashboard' })

      var cidata=JSON.parse(JSON.stringify(this.$route.params))
      console.log(this.$route.params)

      // if(cidata.outTime!=null)
      // {
      //   this.date=cidata.outTime.split(" ")[0]
      //   this.time=cidata.outTime.split(" ")[1]
      // }
      this.username=cidata.username
      this.role=cidata.role
    },
    methods: {
      subadd () {
        if(this.username==''){
          this.showmsg('用户名为空')
          return
        }
        if(this.role==''){
          this.showmsg('权限为空')
          return
        }
        var _this=this
        var fd = new URLSearchParams()
        fd.append('id',this.$route.params.id)
        // if(this.date!=""){
        //   let dt=new Date(this.date+' '+this.time)
        //   fd.append('outTime',dt.toString())
        // }
        fd.append('operatorId',this.$route.params.operatorId)
        fd.append('username',this.username)
        fd.append('role',this.role)
        this.$http.post('http://8.135.35.123:9000/hotelsystem/user/update',fd)
          .then(function(response) {
              if(response.data.code==80200) {
                _this.showmsg('修改成功')
                _this.$router.push({ name: 'management-list' })
              }
              else
                _this.showmsg('修改失败')
            },
            function(err){
              console.log(err)
            }
          )

      },
      back(){
        this.$router.push({ name: 'management-list' })
      },
      showmsg(msg) {
        this.showToast(
          msg,{
            position: 'top-center',
            duration: 2500,
            fullWidth: false,
          },
        )

      }
    },
  }
</script>

<style>
  .row.row-inside {
    max-width: none;
  }
</style>
